package com.cjg.netCode;

import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class net01 {
    public static void main(String[] args) {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            InetAddress byName = InetAddress.getByName("www.baidu.com");
            String hostName = byName.getHostName();
            System.out.println(hostName);//获取域名
            System.out.println(byName.getHostAddress()); // 获取ip
            System.out.println(localHost);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
